<?php
/**
 * User: 鬼一浪人
 * DateTime: 2019/11/11 16:40
 * Description:
 */

declare(strict_types = 1);

namespace App\Http\Controller;

use App\Model\Entity\FormId;
use App\Services\BKDRhash;
use Carbon\Carbon;
use Swoft\Http\Message\Request;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;

/**
 * Class SystemController
 * @Controller()
 * @package App\Http\Controller
 */
class SystemController
{
    /**
     *  @RequestMapping(route="create_form_id")
     * @param Request $request
     * @return string
     * @throws \ReflectionException
     * @throws \Swoft\Bean\Exception\ContainerException
     * @throws \Swoft\Db\Exception\DbException
     */
    public function create_form_id(Request $request)
    {
        $app_id = $request->post('app_id','');
        $open_id = $request->post('open_id','');
        $form_id = $request->post('form_id','');
        if (!$open_id || !$form_id){
            return 'fail';
        }
        $data = [
            'app_id'  => $app_id,
            'user_id' => BKDRhash::hashToInt($open_id),
            'open_id' => $open_id,
            'form_id' => $form_id,
            'created_at' => Carbon::now(new \DateTimeZone('PRC'))
        ];
        FormId::query()->insert($data);
        return 'success';
    }
}
